package br.com.wepa.webapps.security.keys;

import java.io.Serializable;


public class PermissionKey  implements Serializable, Comparable<PermissionKey>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5108545915858000757L;
	private String key;

	public PermissionKey(String key){
		this.key = key;
	}

	
	public PermissionKey(PermissionKey access){
		this(access.getKey());
	}
	
	public String getKey() {
		return key;
	}


	public void setKey(String access) {
		this.key = access;
	}


	@SuppressWarnings("unchecked")
	public int compareTo(PermissionKey o) {
		if(this.key == null){
			return 0;
		}
		return this.key.compareTo(o.key);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof PermissionKey) {
			PermissionKey other = (PermissionKey) obj;
			if(this.key == null){
				return this.key == other.key;
			}else{
				return this.key.equals(other.key);		
			}
		}
		return false;
	}
	
	@Override
	public int hashCode() {			
		return key.hashCode();	
	}

	@Override
	public String toString() {
		return  "PermissionKey=" +key;
	}

	public static void main(String[] args) {
		PermissionKey a = new PermissionKey("abc");
		PermissionKey b = new PermissionKey("abc");
		System.out.println(a.hashCode() + " " + b.hashCode());
	}
}

